﻿using SqliteORM;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NetFrame.Persistance
{
   public class BasePersistance<T>:IDisposable
    {
       public TableAdapter<T> _adapter;

       public TableAdapter<T> Adapter
       {
           get { return _adapter; }
       }

       static BasePersistance()
       {
           DbConnection.Initialise("data source=data");
       }

       public BasePersistance()
       {
           _adapter = TableAdapter<T>.Open();
       }

       public static void DoAction(Action<BasePersistance<T>> action) 
       {
           using (var persistance = new BasePersistance<T>())
           {
               action(persistance);
           }
       }

       public void CreateUpdate(T item)
       {
           _adapter.CreateUpdate(item);
       }

       public void Delete(T item)
       {
           _adapter.Delete(item);
       }

       public void Dispose()
       {
           _adapter.Dispose();
       }
    }
}
